package com.luqm.mall.mallsearch.controller;


import com.lqm.common.exception.BizCodeEnums;
import com.lqm.common.to.es.SkuEsModel;
import com.lqm.common.utils.R;
import com.luqm.mall.mallsearch.service.ProductSaveService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.List;


@Slf4j
@RequestMapping("/search/save")
@RestController
public class ElasticSaveController {

    @Autowired
    private ProductSaveService productSaveService;

    //上架商品
    @PostMapping("/product")
    public R productStatusUp(@RequestBody List<SkuEsModel> skuEsModelLists){
        Boolean b=false;
        try {
            b=productSaveService.productSatusUp(skuEsModelLists);
        } catch (IOException e) {
            log.error("ElasticSaveSearchController商品上架错误:{}",e);
            return R.error(BizCodeEnums.PRODUCT_UP_EXCEPTION.getCode(),BizCodeEnums.PRODUCT_UP_EXCEPTION.getMsg());
        }
        if(b){
            return R.error(BizCodeEnums.PRODUCT_UP_EXCEPTION.getCode(),BizCodeEnums.PRODUCT_UP_EXCEPTION.getMsg());
        }
        return R.ok();
    }
}
